package paperToChaKanChengJi.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;

import com.lancoo.znbkxx.teacher.R;
import com.lancoo.znbkxx.teacher.model.PaperEvaluationEntity;
import com.lancoo.znbkxx.teacher.widget.ScaleButton;

/**
 * auther: 王国龙
 * Date：
 * describe:
 */
public class ExportCommentPathDialog extends Dialog {

    public ExportCommentPathDialog(Context context) {
        super(context);
    }

    private PaperEvaluationEntity paperEvaluationEntity;
    private CallBack callBack;
    public ExportCommentPathDialog(Context context, PaperEvaluationEntity paperEvaluationEntity, CallBack callBack) {
        super(context);
        this.callBack = callBack;
        this.paperEvaluationEntity = paperEvaluationEntity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View view = LayoutInflater.from(getContext()).inflate(R.layout.aibk_dialog_export_comment_path, null);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//加上这一句，取消原来的标题栏，没加这句之前，发现在三星的手机上会有一条蓝色的线
        setContentView(view, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        Window window = getWindow();
        if (window != null) {
            window.setWindowAnimations(R.style.MyDialogScale);//设置动画效果
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        }
        setCanceledOnTouchOutside(true);//禁止点击dialog外部销毁弹窗
        //禁止系统返回键值响应
        setOnKeyListener((dialog, keyCode, event) -> keyCode == KeyEvent.KEYCODE_BACK);

        int stjx_flag = paperEvaluationEntity.getCommentExportTags().getAnswerAnalysis();
        int stzsd_flag = paperEvaluationEntity.getCommentExportTags().getZsd();
        int tlyp_flag = paperEvaluationEntity.getCommentExportTags().getListenVideo();
        int tlyw_flag = paperEvaluationEntity.getCommentExportTags().getListenText();

        LinearLayout mLlStjx = view.findViewById(R.id.ll_stjx);
        LinearLayout mLlStzsd = view.findViewById(R.id.ll_stzsd);
        LinearLayout mLlTlyp = view.findViewById(R.id.ll_tlyp);
        LinearLayout mLlTlyw = view.findViewById(R.id.ll_tlyw);
        CheckBox mCbStjx = view.findViewById(R.id.cb_stjx);
        CheckBox mCbStzsd = view.findViewById(R.id.cb_stzsd);
        CheckBox mCbTlyp = view.findViewById(R.id.cb_tlyp);
        CheckBox mCbTlyw = view.findViewById(R.id.cb_tlyw);
        ScaleButton mSBtnExport = view.findViewById(R.id.sbtn_export);

        if(stjx_flag == 1) {
            mLlStjx.setVisibility(View.VISIBLE);
            mCbStjx.setChecked(true);
        }else{
            mLlStjx.setVisibility(View.GONE);
            mCbStjx.setChecked(false);
        }
        mCbStjx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    mCbStjx.setChecked(true);
                    paperEvaluationEntity.getCommentExportTags().setAnswerAnalysis(1);
                }else{
                    mCbStjx.setChecked(false);
                    paperEvaluationEntity.getCommentExportTags().setAnswerAnalysis(0);
                }
            }
        });

        if(stzsd_flag == 1) {
            mLlStzsd.setVisibility(View.VISIBLE);
            mCbStzsd.setChecked(true);
        }else{
            mLlStzsd.setVisibility(View.GONE);
            mCbStzsd.setChecked(false);
        }
        mCbStzsd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    mCbStzsd.setChecked(true);
                    paperEvaluationEntity.getCommentExportTags().setZsd(1);
                }else{
                    mCbStzsd.setChecked(false);
                    paperEvaluationEntity.getCommentExportTags().setZsd(0);
                }
            }
        });

        if(tlyp_flag == 1) {
            mLlTlyp.setVisibility(View.VISIBLE);
            mCbTlyp.setChecked(true);
        }else{
            mLlTlyp.setVisibility(View.GONE);
            mCbTlyp.setChecked(false);
        }
        mCbTlyp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    mCbTlyp.setChecked(true);
                    paperEvaluationEntity.getCommentExportTags().setListenVideo(1);
                }else{
                    mCbTlyp.setChecked(false);
                    paperEvaluationEntity.getCommentExportTags().setListenVideo(0);
                }
            }
        });

        if(tlyw_flag == 1) {
            mLlTlyw.setVisibility(View.VISIBLE);
            mCbTlyw.setChecked(true);
        }else{
            mLlTlyw.setVisibility(View.GONE);
            mCbTlyw.setChecked(false);
        }
        mCbTlyw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    mCbTlyw.setChecked(true);
                    paperEvaluationEntity.getCommentExportTags().setListenText(1);
                }else{
                    mCbTlyw.setChecked(false);
                    paperEvaluationEntity.getCommentExportTags().setListenText(0);
                }
            }
        });

        mSBtnExport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.Export();
            }
        });

    }

    public interface CallBack {
//        void checkSTJX(int stjx_flag);
//        void checkSTZSD(int stzsd_flag);
//        void checkTLYP(int tlyp_flag);
//        void checkTLYW(int tlyw_flag);
        void Export();
    }

}
